/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-05-06 23:09:53
 * @LastEditors: DESKTOP-D0D7KKT\Administrator 18368095041@163.com
 * @LastEditTime: 2024-11-27 19:10:43
 * @FilePath: \vue3-admin\src\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createApp } from 'vue';
import App from './App.vue';
import router from '@/router';
import { setupStore } from '@/store';
import { setupDirective } from '@/directive';
import { setupElIcons, setupI18n, setupPermission } from '@/plugins';
import { getToken } from '@/utils/auth';

// 本地SVG图标
import 'virtual:svg-icons-register';

// 样式
import 'element-plus/theme-chalk/dark/css-vars.css';
import '@/styles/index.scss';
import 'uno.css';
import 'animate.css';

const app = createApp(App);

let originToken = '';
const setup = () => {
    // 全局注册 自定义指令(directive)
    setupDirective(app);
    // 全局注册 状态管理(store)
    setupStore(app);
    // 全局注册Element-plus图标
    setupElIcons(app);
    // 国际化
    setupI18n(app);
    // 注册动态路由
    setupPermission();
    // 代码编辑器 https://vue-devui.github.io/on-demand/
    // app.use(CodeEditor);
    app.use(router).mount('#app');
    // 判断后台到前台时，token不一致则刷新
    window.addEventListener('visibilitychange', () => {
        const token = getToken();
        if (!token) return;
        if (document.hidden == false) {
            if (originToken !== token) {
                location.reload();
            }
        } else {
            originToken = token;
        }
    });
};

setup();
